<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Table extends CI_Controller {

	 function __construct(){
          parent::__construct();   
     }

  
     function index(){


     	$this->load->model('circle_model');
        $this->load->model('object_model');         
        $this->load->library('PHPExcel');
		$this->load->library('PHPExcel/IOFactory');
  
        $objPHPExcel = new PHPExcel();


        $objPHPExcel->getProperties()->setTitle("export");
        
        // 設定寬度
 
        $objPHPExcel->setActiveSheetIndex(0);
  
        //$query_circle=$this->circle_model->get_c_all(); 
        //$fields = $this->circle_model->get_fields();
        /*

        'market_survey_no' ,'object_no' ,
        'object_state' , 'type_rent' 
        'type_sale' ,'type_help_seal',
        'owner' ,
        owner_mobile
        owner_phone
        market_research_status
        principal
        principal_mobile
        principal_phone
        case_name
        building_name
        object_usage
        object_styles
        administrative_area
        area
        build_number
        sale_total
        sale_parking
        sale_housing_prices
        sale_housing_unit_price
        sale_parking_price
        sale_parking_unit_price
        sale_land_unit_price
        rent_total
        rent_parking
        rent_housing_rent
        rent_parking_space_rentals
        rent_rent_per_ping
        rent_monthly_rent_parking_spaces
        rent_deposit_month
        rent_min
        rent_max
        rent_lease_hike
        rent_rent_free_period_decoration
        rent_ancillary
        rent_notarization
        building_area
        main_building_area
        subsidiary_building_area
        postulate
        total_weight_shaped_area
        with_parking_number
        parking_area_number
        use_area
        postulate_than
        base_is_located1
        base_is_located2
        to_no
        base_area
        scope_of_rights1
        scope_of_rights2
        stakeholders_land_area
        present_value
        total_present_value1
        total_present_value2
        land_use_zoning

        */
        $query_circle=$this->object_model->get_c_all(); 
        $fields = $this->object_model->get_fields();

        $col = 0;
         
        foreach ($fields as $field){
         	
            $objPHPExcel->
            	getActiveSheet()->
            	setCellValueByColumnAndRow($col, 1, $field);

            $col++;

        }

  		
        // Fetching the table data
        $row = 2;
        foreach($query_circle->result() as $cir){

             $col = 0;
             foreach ($fields as $field)
             {
                 $objPHPExcel->
                 	getActiveSheet()->
                 	setCellValueByColumnAndRow($col, $row, $cir->$field.' ');
                 $col++;
             }
  
             $row++;
        }
  
        $objPHPExcel->setActiveSheetIndex(0);
  
        $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
  
        // Sending headers to force the user to download the file
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.date('dMy').'.xls"');
        header('Cache-Control: max-age=0');
        $objWriter->save('php://output');
        
     }





     function  qc(){

        echo 'eetest';


     }
	

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */